home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
Point.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-27
|
3KB
|
145 lines
#ifdef __GNUG__
#pragma implementation
#endif
#define FakeExternalDecl
#include "Point.h"
#include "Class.h"
#include "Math.h"
#include "String.h"
/* In order to become independent from the order of global constructors
we fake C++ by using plain old C (which gets initialized by the loader)
*/
struct C_Point {
int x, y;
};
C_Point gPoint_1 = { -1, -1 },
gPoint0,
gPoint1 = { 1, 1 },
gPoint2 = { 2, 2 },
gPoint3 = { 3, 3 },
gPoint4 = { 4, 4 },
gPoint5 = { 5, 5 },
gPoint6 = { 6, 6 },
gPoint7 = { 7, 7 },
gPoint8 = { 8, 8 },
gPoint10 = { 10, 10 },
gPoint16 = { 16, 16 },
gPoint32 = { 32, 32 },
gPoint64 = { 64, 64 };
SimpleMetaImpl(Point)
{
len= len;
if (! isptr)
sprintf(buf, "%s", ((Point*) addr)->AsString());
}
Point Min(Point p1, Point p2)
{
return Point(Math::Min(p1.x, p2.x), Math::Min(p1.y, p2.y));
}
Point Max(Point p1, Point p2)
{
return Point(Math::Max(p1.x, p2.x), Math::Max(p1.y, p2.y));
}
Point Range (Point lb, Point ub, Point x)
{
return Point(Math::Range(lb.x, ub.x, x.x), Math::Range(lb.y, ub.y, x.y));
}
Point Point::Half() const
{
return Point(x >> 1, y >> 1);
}
Point Half (Point p)
{
return Point(p.x/2, p.y/2);
}
Point Abs(Point p)
{
return Point(Math::Abs(p.x), Math::Abs(p.y));
}
Point Sign(Point p)
{
return Point(Math::Sign(p.x), Math::Sign(p.y));
}
Point Scale(Point p, Point num, Point denom)
{
Point r;
if (denom.x)
r.x= (int)((float)(p.x*num.x) / (float)denom.x + 0.5);
if (denom.y)
r.y= (int)((float)(p.y*num.y) / (float)denom.y + 0.5);
return r;
}
Point Scale(Point p, float sx, float sy)
{
return Point((float)((p.x*sx)+0.5), (float)((p.y*sy)+0.5));
}
float Phi(Point p)
{
return Math::Atan2(p.y, p.x);
}
float Length(Point p)
{
return (float) Math::Hypot(p.x, p.y);
}
Point PolarToPoint(double ang, double fx, double fy)
{
double si, co;
Math::Sincos(ang, &si, &co);
return Point((int)(fx*co+0.5), (int)(fy*si+0.5));
}
Point polartopoint(double ang, double fx, double fy)
{
double si, co;
Math::Sincos(ang, &si, &co);
return Point((int)(fx*co+0.5), (int)(fy*si+0.5));
}
void Swap(Point &p1, Point &p2)
{
Point tmp= p1;
p1= p2;
p2= tmp;
}
Point Flip(Point &p)
{
return Point(p.y, p.x);
}
OStream& operator<< (OStream &s, Point p)
{
return s << p.x SP << p.y SP;
}
IStream& operator>> (IStream& s, Point& p)
{
return s >> p.x >> p.y;
}
char *Point::AsString() const
{
return form("x: %d y: %d", x, y);
}